// Header Protection
#ifndef _MUTEX_H_
#define _MUTEX_H_

// Include Files
#include "Definitions.h"
#include <Windows.h>

// Namespace
namespace IE
{
	/////////////////////////////////////////////////////////////////////////////////
	// A critical section which can only be locked by one thread at a time.
	class mutex_t
	{
	public:     // methods
		mutex_t() { InitializeCriticalSection(&m_hMutex); }
		~mutex_t() { DeleteCriticalSection(&m_hMutex); }

		// Locks the mutex, if it is already locked on another thread, this method 
		//     will wait until it is unlocked before returning.
		void Lock() { EnterCriticalSection(&m_hMutex); }

		// Attempts to lock the mutex, if it is already locked on another thread, 
		//     this method will return false.
		// return: bool_t - whether or not the lock attempt was successful.
		bool_t TryLock() { return TryEnterCriticalSection(&m_hMutex) != 0; }

		// Unlocks the mutex so it can be locked by another thread.
		void Unlock() { LeaveCriticalSection(&m_hMutex); }

	private:    // dummy definitions
		mutex_t( mutex_t const & );
		mutex_t &operator =( mutex_t const & );

	private:    // data
		CRITICAL_SECTION m_hMutex;
	};
}

// Header Protection
#endif // _MUTEX_H_
